package com.wudimeng.syll.controller.api;


import com.wudimeng.syll.common.ApiResponse;
import com.wudimeng.syll.constants.Constant;
import com.wudimeng.syll.entity.CChuKuXinXi;
import com.wudimeng.syll.entity.CRuKuXinXi;
import com.wudimeng.syll.service.ICChuKuXinXiService;
import com.wudimeng.syll.service.ICRuKuXinXiService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author laohei
 * @Date 2020/6/8 9:50
 * @Version 1.0
 */
@RestController
@Slf4j
@RequestMapping("syll")
public class CChuKuXinXiController {

    @Autowired
    private ICChuKuXinXiService service;

    @GetMapping("/ChuKuXinXi")
    public ApiResponse getChuKuXinXi(HttpServletRequest  request){
        try {
            Map<String,String> map = new HashMap<>();
            map.put("startDate",request.getParameter("startDate"));
            map.put("endDate",request.getParameter("endDate"));
            map.put("ChanPinMingCheng",request.getParameter("ChanPinMingCheng"));
            map.put("LengKu",request.getParameter("LengKu"));
            map.put("GuoChanHuoJinKouChuKu",request.getParameter("GuoChanHuoJinKouChuKu"));
            map.put("YongHuID",request.getParameter("YongHuID"));
            map.put("WeiTuoID",request.getParameter("WeiTuoID"));
            Integer pageNum = Integer.valueOf(request.getParameter("pageNum"));
            Integer pageSize = Integer.valueOf(request.getParameter("pageSize"));
            return this.service.selectCChuKuXinXi(map,pageNum,pageSize);
        } catch (Exception e) {
            log.error("ChuKuXinXi.getChuKuXinXi.请稍后再试:" + e.getMessage());
            return ApiResponse.error(Constant.COMMON_PARAMETER_DEGRADE);
        }
    }

    @PostMapping("/ChuKuXinXi")
    public ApiResponse addChuKuXinXi(@RequestBody CChuKuXinXi chuKuXinXi, HttpServletRequest request){
        return service.addCChuKuXinXi(chuKuXinXi);
    }

    @PutMapping("/ChuKuXinXi")
    public ApiResponse updChuKuXinXi(@RequestBody CChuKuXinXi chuKuXinXi, HttpServletRequest request){
        return service.updCChuKuXinXi(chuKuXinXi);
    }

    //单独修改 is_RK
    @PostMapping("/changeIsRk")
    public ApiResponse changeIsRk(@RequestBody CChuKuXinXi chuKuXinXi, HttpServletRequest request){
        return service.changeIsRk(chuKuXinXi.getLiuShuiHao());
    }

    @DeleteMapping ("/ChuKuXinXi")
    public ApiResponse delChuKuXinXi(String liuShuiID, HttpServletRequest request){
        return service.delCChuKuXinXi(liuShuiID);
    }

    @GetMapping("/getChuKuXinXiByLiuShuiHao")
    public ApiResponse getChuKuXinXiByLiuShuiHao(HttpServletRequest request){
        try {
            return service.selectCChuKuXinXiByLiuShuiHao(request.getParameter("liuShuiHao"),request.getParameter("liuShuiID"));
        } catch (Exception e) {
            e.printStackTrace();
            return ApiResponse.error(Constant.COMMON_OPERATE_FAIL);
        }
    }

    @GetMapping("/getChuKuLiuShuiHao")
    public ApiResponse getChuKuLiuShuiHao(HttpServletRequest request){
        try {
            return service.getChuKuLiuShuiHao(request.getParameter("liuShuiHao"));
        } catch (Exception e) {
            e.printStackTrace();
            return ApiResponse.error(Constant.COMMON_OPERATE_FAIL);
        }
    }

    /**
     * 追溯信息
     * @param request
     * @return
     */
    @GetMapping("/getZhuiSuXinXiLiuShuiID")
    public ApiResponse getZhuiSuXinXiLiuShuiID(HttpServletRequest request){
        return service.getZhuiSuXinXiLiuShuiID(request.getParameter("liuShuiID"));
    }
}
